<?php

class UserController extends \BaseController {

    /**
     * 注册用户
     * username 用户名
     * password 用户密码
     * @return [array] [异常信息]
     */
    public function create(){
        // $username = Input::get('username');
        // $password = Input::get('password');
        $data = Input::all();
        $rules = array(
                    'username' => 'required|unique:users,username',
                    'password' => 'required'
                );
        BaseService::validateInputParam($data, $rules);
        $result = UserService::create($data);
        return $result;
    }

    /**
     * 用户登录
     * username 用户名
     * password 用户密码
     * @return [array] [异常信息]
     */
    public function login(){
        // $username = Input::get('username');
        // $password = Input::get('password');
        $data = Input::all();
        $rules = array(
                    'username' => 'required|exists:users,username',
                    'password' => 'required'
                );
        BaseService::validateInputParam($data, $rules);
        $result = UserService::login($data);
        return $result;
    }

    public function logout(){
        Sentry::logout();
        return BaseService::getResult('logout successful');
    }

}